package rx.authentication.model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Users{
	private List list;
	public Users(){
		this.list = new ArrayList(5);
	}
	private Users(List list){
		this.list = list;
	}
	public void addUser(User user){
		list.add(user);
	}
	
	public void addUsers(Users users){
		list.addAll(users.list);
	}
	
	public Iterator iterator(){
		return list.iterator();
	}
	public User getUser(String username){
		for(Iterator iter = this.iterator();iter.hasNext();){
			User user = (User)iter.next();
			if(user.getUsername().equals(username)){
				return user;
			}
		}
		return null;
	}
	public Users sub(int form,int to){
		return new Users(list.subList(form,to));
	}
	public int size(){
		return list.size();
	}
	
	public List toUsernameList(){
		List result=new ArrayList();
		for(Iterator iter=this.iterator();iter.hasNext();){
			User user=(User)iter.next();
			result.add(user.getUsername());
		}
		return result;
	}
	
	
}
